package hikari.gui.guicomponents;

import java.awt.FlowLayout;
import javax.swing.JPanel;
import com.gooddies.swing.HToggleButton;
import com.gooddies.wiring.annotations.Wire;
import com.gooddies.wiring.annotations.WiringComponent;
import hikari.managers.ActionManager;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.border.BevelBorder;

/**
 * @author sad
 */
@WiringComponent
public class HToolbar extends JPanel {

    @Wire
    private ActionManager actionManager;
    private int iconSizes = 25;
    

    private HToolbar() {
        setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
        setLayout(new FlowLayout(FlowLayout.LEFT, 2, 0));
        setPreferredSize(new Dimension(200, 30));
    }

    public int getIconSizes() {
        return iconSizes;
    }

    public void setIconSizes(int iconSizes) {
        this.iconSizes = iconSizes;
    }

    public HToggleButton addButton(String tooltip, String action, BufferedImage icon) {
        final HToggleButton button = new HToggleButton(icon);
        button.setAction(action);
        button.setToolTipText(tooltip);
        button.setOnSelect(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    actionManager.invokeAction(button.getAction());
                } catch (Exception exception) {
                    exception.printStackTrace();
                }
            }
        });

        button.setPreferredSize(new Dimension(iconSizes, iconSizes));
        add(button);
        return button;
    }
    public JButton addSimpleButton(String tooltip, String action, BufferedImage icon) {
        final JButton button = new JButton(new ImageIcon(icon));
        button.putClientProperty("action", action);
        button.setToolTipText(tooltip);
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    actionManager.invokeAction((String)button.getClientProperty("action"));
                } catch (Exception exception) {
                    exception.printStackTrace();
                }
            }
        });

        button.setPreferredSize(new Dimension(iconSizes, iconSizes));
        add(button);
        return button;
    }

    public void addSeparator() {
        JPanel separator = new JPanel();
        separator.setPreferredSize(new Dimension(3, iconSizes));
        separator.setBackground(Color.WHITE);
        add(separator);
    }
}
